package org.dreamwork.jasmine2.sample.page;

import org.dreamwork.jasmine2.editor.ckeditor.controls.CKEditorControl;
import org.dreamwork.jasmine2.events.EventException;
import org.dreamwork.jasmine2.events.IClickListener;
import org.dreamwork.jasmine2.events.IValidateListener;
import org.dreamwork.jasmine2.web.IWebControl;
import org.dreamwork.jasmine2.web.controls.Button;
import org.dreamwork.jasmine2.web.controls.InternalJS;
import org.dreamwork.jasmine2.web.controls.Page;
import org.dreamwork.jasmine2.web.controls.TextBox;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 12-7-3
 * Time: 下午3:00
 */
public class EditorPage extends Page {
    protected TextBox subject;
    protected Button btnOK;
    protected CKEditorControl editor;

    protected Map<String, String> map = new HashMap<String, String> ();

    @Override
    public void onPagePreload (Page page) throws EventException {
        registerClientScriptBlock (InternalJS.class, InternalJS.LOGGER_JS);
        btnOK.addClickListener (new IClickListener() {
            public void onClick (IWebControl sender) throws EventException {
                System.out.println (editor.getHtml ());
                System.out.println ("======================================");
                System.out.println (editor.getImageSources ());
            }
        });

        subject.addValidateListener (new IValidateListener() {
            public boolean onValidate (IWebControl sender) {
                return false;
            }
        });

        map.put ("html", "<div style='color:#f00;font-size:36px;'>Bound Data</div>");
    }

    @Override
    public void onPageLoad (Page page) throws EventException {
        super.onPageLoad (page);
    }

    @Override
    public void onPageLoadCompleted (Page page) throws EventException {
        super.onPageLoadCompleted (page);

        if (page.isPostback ()) {
            System.out.println (editor.getHtml ());
            System.out.println ("======================================");
            System.out.println (editor.getImageSources ());
        }

        try {
            dataBind ();
        } catch (Throwable throwable) {
            throwable.printStackTrace ();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
}